package com.sky.config;

import com.obs.services.ObsClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "sky.hwoss")
public class OBSConfig {
    private String accessKey;
    private String securityKey;
    private String endPoint;
    private String bucketName;

    @Bean
    public ObsClient obsClient() {
        // 处理endPoint，确保不包含协议前缀
        String endpoint = endPoint;
        if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
            endpoint = endpoint.substring(endpoint.indexOf("://") + 3);
        }
        return new ObsClient(accessKey, securityKey, endpoint);
    }
}
